package com.ourteam.product.api;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ourteam.frame.controller.AbstractCRUDServiceController;
import com.ourteam.product.ui.dao.ProductUITableColumnDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUITableColumnBean;
import com.ourteam.product.ui.service.IProductUIService;
import com.ourteam.product.ui.service.ProductUIServiceFactory;

@Controller
@RequestMapping("/api/PRODUCT/UI/productUITableField")
public class ProductUITableFieldAPI extends
		AbstractCRUDServiceController<ProductUITableColumnDAOQueryBean, ProductUITableFieldSearchModel, ProductUITableColumnBean> {

	private static final IProductUIService PRODUCT_UI_SERVICE = ProductUIServiceFactory.getProductUIService();

	@Override
	protected ProductUITableColumnDAOQueryBean newQueryBean() {
		return new ProductUITableColumnDAOQueryBean();
	}

	@Override
	protected int queryCount(ProductUITableColumnDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUITableColumnCount(queryBean);
	}

	@Override
	protected ProductUITableColumnBean[] queryData(ProductUITableColumnDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUITableColumns(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {
		PRODUCT_UI_SERVICE.deleteProductUITableColumns(ids);
	}

	@Override
	protected ProductUITableColumnBean getDataById(long id) throws Exception {
		return PRODUCT_UI_SERVICE.getProductUITableColumnById(id);
	}

	@Override
	protected void saveData(ProductUITableColumnBean dataBean) throws Exception {
		dataBean.setLastModifyTime(new Date());
		dataBean.setLastModifyUser(getLoginUserName());
		if (dataBean.getId() == 0) {
			PRODUCT_UI_SERVICE.addNewProductUITableColumn(dataBean);
		} else {
			PRODUCT_UI_SERVICE.modifyProductUITableColumn(dataBean);
		}
	}

}
